package com.hdu;

import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class Task implements Runnable {

    private static final Logger log = LoggerFactory.getLogger(Task.class);
    @Getter
    private final int id;

    public Task(int id) {
        this.id = id;
    }

    @Override
    public void run() {
        try {
            TimeUnit.SECONDS.sleep(1);
            System.out.println("第 " + id + " 次开始执行");
        } catch (InterruptedException e) {
            // 相应中断
            // 重置打断标记
            Thread.currentThread().interrupt();
            if (Thread.currentThread().isInterrupted()) {
                log.info("第 {} 次任务被打断了", id);
            }
        }
    }
}
